package cn.yikaojiuguo.student.ui.global;

import android.util.SparseArray;

import cn.yikaojiuguo.student.ui.ask.AskFragment;
import cn.yikaojiuguo.student.ui.base.BaseFragment;
import cn.yikaojiuguo.student.ui.my.MyFragment;

/**
 * Created by cfan_yang on 2015/12/21.
 * 负责HomeActivity中几个Fragment的工厂类
 */
public class HomeFragmentFactory {

    //Fragment数量
    public final static int FRAGMENT_COUNT = 3;
    private static SparseArray<BaseFragment> fragments = new SparseArray<BaseFragment>(FRAGMENT_COUNT);

    //初始化SparseArray
    static {
        fragments.put(0,new AskFragment());
        fragments.put(1,new CourseFragment());
        fragments.put(2,new MyFragment());
    }
    public static BaseFragment getFragment(int position) {
        BaseFragment baseFragment = fragments.get(position);
        if(baseFragment == null) {
            switch (position) {
                case 0:
                    baseFragment = new AskFragment();
                    break;
                case 1:
                    baseFragment = new CourseFragment();
                    break;
                case 2:
                    baseFragment = new MyFragment();
                    break;
            }
            fragments.put(position,baseFragment);
        }
        return baseFragment;
    }
}
